//
//  CommonTool.m
//  Project
//
//  Created by  CarlsonLee on 2018/12/7.
//  Copyright © 2018年 YANJING. All rights reserved.
//

#import "CommonTool.h"
#import "NSString+LTDate.h"

@implementation CommonTool

NSString* fontName(FONT_TYPE tp){
    switch (tp) {
        case FONT_TYPE_REGULAR:{
            return @"PingFangSC-Regular";
        }
            break;
        case FONT_TYPE_MEDIUM:{
            return @"PingFangSC-Medium";
        }
            break;
        case FONT_TYPE_LIGHT:{
            return @"PingFangSC-Light";
        }
            break;
        case FONT_TYPE_DISPLAY:{
            return @".SFNSDisplay";
        }
            break;
        case FONT_TYPE_DIN:{
            return @"DIN-Regular";
        }
            break;
        case FONT_TYPE_LED:{
            return @"UnidreamLED";
        }
            break;
        default:
            break;
    }
}


/**
 *
 */
UIFont* XNFont(CGFloat size, FONT_TYPE tp){
    UIFont* font = [UIFont fontWithName:fontName(tp) size:size*kScaleX];
    if(!font){
        font = [UIFont systemFontOfSize:size*kScaleX];
    }
    return font;
}

/**
 *  初始化label
 */
id XN_BNEW_LABEL(UIColor* _bg_color_, UIColor* _text_color_, UIFont* _font_, NSTextAlignment _type_, NSInteger _lines_, id _superView_){
    UILabel* _object_name_ = [[UILabel alloc]init];
    [_object_name_ setBackgroundColor:_bg_color_?_bg_color_:[UIColor clearColor]];
    [_object_name_ setTextColor:_text_color_];
    [_object_name_ setFont:_font_];
    [_object_name_ setTextAlignment:_type_];
    [_object_name_ setNumberOfLines:_lines_];
    //    [_object_name_ setAdjustsFontSizeToFitWidth:YES];
    if(_superView_)[_superView_ addSubview:_object_name_];
    return _object_name_;
}

+ (NSArray* )ct_creatImageArrWithBaseStr:(NSString* )str beginIdx:(NSInteger)bIdx endIdx:(NSInteger)eIdx
{
    NSMutableArray* imgArr = @[].mutableCopy;
    for(NSInteger i=bIdx; i<=eIdx; i++){
        NSString* imgStr = [NSString stringWithFormat:@"%@%ld", str, i];
        [imgArr addObject:XN_IMG(imgStr)];
    }
    return imgArr.copy;
}

+ (BOOL)ct_judgeContainTimeFrom:(NSString* )fTime to:(NSString* )tTime
{
    NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
    NSString* todayStr = [NSString stringFMD:@"yyyy/MM/dd" withTimeInterval:time];
    NSString* t1 = [NSString stringWithFormat:@"%@ %@", todayStr, fTime];
    NSString* t2 = [NSString stringWithFormat:@"%@ %@", todayStr, tTime];
    NSString* eTime = [NSString stringFMD:@"yyyy/MM/dd HH:mm" withTimeInterval:time];
    if([eTime compare:t1]==NSOrderedDescending && [eTime compare:t2]==NSOrderedAscending){
        return YES;
    }
    return NO;
}

@end
